package edu.ycxy.poetry.controller;


import com.github.pagehelper.PageInfo;
import edu.ycxy.poetry.entity.DjList;
import edu.ycxy.poetry.service.IDjListService;
import edu.ycxy.poetry.vo.AddDjVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author @xin
 * @createDate 2022/3/14
 * @Description
 */
@RestController
@RequestMapping("/djList")
@Slf4j
public class DjListController {

    @Autowired
    private IDjListService djListService;

    //查询所有的古籍内容
    @RequestMapping("/selectList")
    public PageInfo<DjList> selectListByDjList(Integer pageNum){
        if (pageNum == null){
            pageNum = 1;
        }
        PageInfo<DjList> djListPageInfo = djListService.selectListByDjList(pageNum, 20);
        log.debug("查询出古籍的全部内容:"+djListPageInfo);
        return djListPageInfo;
    }

    //根据古籍的id查询古籍的内容
    @RequestMapping("/selectOne/{id}")
    public DjList selectOne(@PathVariable("id") Integer id){
        log.debug("根据id查询古籍的内容为:"+djListService.selectOneById(id));
        return djListService.selectOneById(id);
    }

    //根据古籍的类型名查找古籍符合条件的内容
    @RequestMapping("/selectByType/{type}")
    public List<DjList> selectListByType(@PathVariable("type") String type){
        log.debug("根据类型获取的古籍名: " + djListService.selectListByType(type));
        return djListService.selectListByType(type);
    }

    //添加古籍信息
    @RequestMapping("/addDj")
    public Integer AddDj(@RequestBody AddDjVo addDjVo){
        log.debug("获取到的内容:" + addDjVo);
        String s = djListService.addDj(addDjVo);
        if (s.equals("ok")){
            return 1;
        }else {
            return 2;
        }
    }
}
